#!/bin/bash

# Test md disk failure with node change events

. ./common

_need_to_be_root

_make_device 0 $((300 * 1024 ** 2))
_make_device 1 $((300 * 1024 ** 2))
_make_device 2 $((300 * 1024 ** 2))
_make_device 3 $((300 * 1024 ** 2))
_make_device 4 $((300 * 1024 ** 2))
_make_device 5 $((300 * 1024 ** 2))
_make_device 6 $((300 * 1024 ** 2))

MD=true

for i in `seq 0 5`; do
	_start_sheep $i
done
_wait_for_sheep 6
_cluster_format
_vdi_create test 200M -P

# node event after disk failure
_safe_remove $STORE/0/d0

_random | $DOG vdi write test &
sleep 1
_start_sheep 6
_wait_for_sheep 7
_wait_for_sheep_recovery 0
wait # dog
$DOG vdi check test
$DOG cluster info | _filter_cluster_info

# disk failures after node event
_safe_remove $STORE/1/d0
dd if=/dev/zero | $DOG vdi write test &
sleep 1
_kill_sheep 2
_wait_for_sheep 6
_safe_remove $STORE/1/d1
_wait_for_sheep_recovery 0
wait # dog
$DOG vdi check test
$DOG cluster info | _filter_cluster_info
